home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 March - Disc 1 / Macworld (1999-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Help / ElecCompletions Help < prev    next >
Encoding:
Text File  |  1998-07-25  |  17.0 KB  |  454 lines  |  [TEXT/ALFA]

  1. ## 
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "ElecCompletions Help"
  6.  #                                    created: 1/8/97 {2:24:21 pm} 
  7.  #                                last update: 25/7/98 {12:40:32 am} 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <darley@fas.harvard.edu>
  10.  #    mail: Division of Engineering and Applied Sciences, Harvard University
  11.  #          Oxford Street, Cambridge MA 02138, USA
  12.  #     www: <http://www.fas.harvard.edu/~darley/>
  13.  #  
  14.  # Copyright (c) 1997-98  Vince Darley
  15.  # Some pieces pasted from Alpha-D mailing list responses.
  16.  # ###################################################################
  17.  ##
  18.  
  19.  
  20. The idea with electric completions is to save you key strokes. When you hit
  21. cmd-tab Alpha tries to expand what you have just typed to give the rest of
  22. what you want (the choice of cmd-tab can be adjusted in the 
  23. 'Config->Global->Special Keys' dialog).
  24.  
  25. If you want basic help/tutorial information, do the following: when 
  26. you're in a mode for which you want a tutorial on electric completions,
  27. select 'Completions Tutorial' from the 'Current mode' menu.  Follow 
  28. the instructions there.
  29.  
  30. Recent changes:
  31.  
  32. The code has been split into separate packages.  The better templates code 
  33. is now optional --- it is slow on slow machines so some people prefer not
  34. to use it, but still like all the electric completions etc.  The problem
  35. is that the standard template code lacks some of the more advanced features
  36. of my version.
  37.  
  38. You can modify the following preferences using the 
  39. 'Config->Global->Flags->Electrics' menu item:
  40.  
  41.     • useElectricMenu --- use electric template menu 
  42.     • showElectricsInMenu --- show electric completions in menu 
  43.     • showElectricKeysInMenu --- show electric key bindings in menu
  44.     • modeSpecificElecTab --- use mode-specific electric tab 
  45.     • electricTab --- use electric tab 
  46.     • templateStopColor --- colour of template stops 
  47.     • listPickIfMultExpds --- similarly for expansions 
  48.     • ElectricFillers --- The format of the template stops:
  49.           0 = just use bullets
  50.           1 = use bullets but signal the name in the status window
  51.           2 = insert names into the window with the bullets
  52.           3 = insert names and highlight into the window with the bullets
  53.     • maxTemplateNesting--- level of nesting we allow before clearing 
  54.  
  55. The electric menu contains a 'Templates' sub-menu, which contains global 
  56. templates stored in the variable 'univ::MenuTemplates', and mode-specific
  57. templates stored in variables ${mode}Templates.  The format of these 
  58. variables is a list of names, which correspond to procedures when prepended 
  59. with 'file::'.  You can add new items by using the menu item.
  60.  
  61.           Templates
  62.  
  63. Many of the routines in Vince's Additions allow you to insert templates for 
  64. 'for' loops, '\begin...\end environments', file headers, function comments, 
  65. and even entire documents.  This section details the features of Vince's 
  66. Additions which allow you to do that.  Here's an example of a 'for' template
  67. in C++ mode (created just by typing 'for<cmd-Tab>'):
  68.  
  69.     for (•<init>;•<test>;•<increment>){
  70.         •<loop body>
  71.     }
  72.     •
  73.  
  74. Once a template has been inserted, it will often contain a number of 
  75. 'place-markers' or 'template-stops' at each of which you will most likely 
  76. wish to enter some text/code.  You can jump backwards and forwards amongst 
  77. these stops using a set of key bindings.  You have a choice between two 
  78. basic sets (you select using the 'Electric Bindings' dialog):
  79.  
  80.     Operation               Standard Bindings         Alternative Set
  81.  
  82.     "Next Stop Or Tab"       Tab                       ctrl-j      
  83.     "Complete"               cmd-Tab                   cmd-Tab     
  84.     "Expand"                 cmd-Space                 Tab 
  85.     "Prev Stop"              shift-Tab                 shift-ctrl-j        
  86.     "Real Tab"               opt-Tab                   opt-Tab
  87.     "nth Stop"               ctrl-Tab                  ctrl-opt-j          
  88.     "Clear All Stops"        shift-ctrl-Tab            shift-ctrl-opt-j            
  89.  
  90. Furthermore you can redefine any of these bindings using that same
  91. dialog.
  92.  
  93. You have a choice between four different formats for the visual appearance 
  94. of the template-stops.  They are usually signified by a bullet '•', but 
  95. more elaborate methods are supported.  These templates may be nested 
  96. without any extra effort on your part.  Most of this code is contained in 
  97. the file "betterTemplates.tcl", although all the bindings and initialisation 
  98. are in "elecBindings.tcl".
  99.  
  100. Look at the new 'electric' menu for a list of these bindings, together 
  101. with some other functions.
  102.  
  103. ================================================================================
  104.  
  105.           Completions
  106.  
  107. I've now written a unified collection of procedures to address command 
  108. completion, code indentation, electric-code generation, word completion and 
  109. related facilities (incorporating my old TeX-reference completion for 
  110. example). 
  111.  
  112. Here's a typical example from TeX mode, I type:
  113.  
  114.     for an explanation of this phenomenon,
  115.     please refer to Fig<cmd-Tab>
  116.     
  117. The <cmd-Tab> signifies that Vince's Additions should try to complete the 
  118. currently typed text.  In this case the completion is:
  119.  
  120.     for an explanation of this phenomenon,
  121.     please refer to Figure~\ref{fig-
  122.     
  123. If I hit <cmd-Tab> again, Vince's Additions tries to search for TeX 
  124. '\labels' which begin with 'fig-' to insert the first such label
  125. it finds into the text:
  126.  
  127.     for an explanation of this phenomenon,
  128.     please refer to Figure~\ref{fig-heat-vs-time}
  129.     
  130. If this is the wrong one, I can keep hitting <cmd-Tab> until I reach the 
  131. correct completion:
  132.  
  133.     for an explanation of this phenomenon,
  134.     please refer to Figure~\ref{fig-explanation}
  135.     
  136. Here's an example from C/C++ modes. I type 'for<cmd-Tab>' and get:
  137.  
  138.     for (;•;•){
  139.         •
  140.     }
  141.  
  142. This works at any current level of indentation, and the bullet marks '•' 
  143. are placemarkers.  You can just press 'Tab' (without 'cmd') to jump from 
  144. one to the next.
  145.  
  146. These facilities are activated as follows:
  147.  
  148. •    Tab --- plain - either 'indent' or 'next template mark'
  149.             cmd   - complete the current text.
  150.             opt   - insert a real tab.
  151.                         
  152. So, pressing Tab by default will _not_ necessarily insert a tab, rather it 
  153. will indent the current line of code to the correct indentation level to 
  154. match the code around it.  
  155.  
  156.             Types of completion
  157.  
  158.  
  159. Command-Tab has a number of different meanings, which will be explained 
  160. below.  Completions are listed in order of precedence.
  161.  
  162.               User completion: 
  163.  
  164. all entries defined in the array 'userCompletions' are checked and inserted 
  165. if appropriate.  This is useful to make 'vmd' turn into 'Vince Darley', or 
  166. 'www' into my home-page url, or ...
  167.     
  168. User completions are active in all modes, and take precedence over all 
  169. other completion types.
  170.  
  171.               Context sensitive completion: 
  172.  
  173. Context sensitive completions are mode dependent.  In some modes you 
  174. can tell relatively easily from the context whether a particular 
  175. 'word' is a variable or procedure name or...  If different completion
  176. procedures are useful for different types of word, then they are 
  177. checked next.  For instance, in Tcl mode, a word beginning with '$',
  178. or preceded by 'set' or 'global' is a variable name.  It should 
  179. therefore be completed preferentially as a variable, rather than
  180. being expanded as a command.  E.g. $str should normally not be
  181. expanded to '$string ...' since it's clearly not the command 'string' 
  182. that the user is trying to type.  
  183.  
  184.               Command completion: 
  185.  
  186. For instance: type 'str<cmd-tab>' and it is completed to 'string' (in Tcl 
  187. mode).  If there are multiple possibilities then the longest unique prefix 
  188. is inserted.
  189.     
  190. The available completions are mode dependent, and stored as a large string 
  191. in the variable ${mode}cmds.  They must be stored alphabetically, and
  192. be separated by whitespace.  THERE IS NO LONGER A NEED TO BEGIN AND
  193. END THE LIST WITH WHITESPACE.
  194.  
  195. Here is the default value for Tcl mode:
  196.  
  197.     set Tclcmds { append array catch close concat continue elseif error
  198.     for foreach format lindex lsearch lsort regexp regsub
  199.     rename return string switch while }
  200.  
  201.               Ensemble completion: 
  202.  
  203. type 'string co<cmd-Tab' and this is both completed to 'string compare' and 
  204. an electric template is inserted for the arguments of this two part 
  205. command.  Useful for any case in which the word before last is the command, 
  206. and the word just before is part of a refinement of that command, in any 
  207. situation for which a number of further arguments will be filled in.
  208.     
  209.               Electric code template generation: 
  210.  
  211. type 'for<cmd-tab>' and a complete template for code is generated (example 
  212. for C mode):
  213.     
  214.     for (;•;•){
  215.         •
  216.     }
  217.  
  218. You can move from one template mark '•' to the next with, plain 'Tab' - 
  219. I automatically sense whether a template insertion is in progress or
  220. not and interpret tab accordingly.
  221.  
  222. These are again mode dependent. Each is stored individually as an element 
  223. of the array ${mode}electrics, so, for instance the above electric code is 
  224. generated by:
  225.  
  226.     set Celectrics(for) " (••;••;••)\{\n\t••\n\}\n••"
  227.  
  228. Note how the bullets are double in the definition.  You can actually place 
  229. an explanatory bit of text between pairs of bullets.  This is then used as 
  230. a hint to the user:
  231.  
  232.     set Celectrics(for) " (•start•;•test•;•increment•)\{\n\t•body•\n\}\n••"
  233.  
  234.               Class name completion: 
  235.  
  236. In C++ mode, when entering a class definition, the class name occurs 
  237. multiple times.  To save entering all of these, this completion will
  238. fill them all in for you.  It works like this: type 'class<cmd-tab>'
  239.  
  240.     class •<object name> : public •<parent> {
  241.       public:
  242.         •<object name>(•<args>);
  243.         ~•<object name>(void);
  244.     
  245.     };
  246.     •
  247.  
  248. Now type the class name, say 'toaster', followed by <cmd-tab>.  This
  249. will result in:
  250.  
  251.     class toaster : public •<parent> {
  252.       public:
  253.         toaster(•<args>);
  254.         ~toaster(void);
  255.     
  256.     };
  257.     •
  258.  
  259. i.e. each occurrence of the electric stop 'object name' has been 
  260. filled in correctly.  This feature may be easily extended to more
  261. complex examples.
  262.  
  263.               TeX reference completion: 
  264.  
  265. type '\ref<cmd-Tab>' and the command is automatically completed with the 
  266. name of a nearby \label{}.  Repeated <cmd-Tab> keypresses will cycle 
  267. through all \label's.  Further, these commands chain together, so typing 
  268. '\eqr<cmd-Tab>' will complete the \eqref and continue to fill in a nearby 
  269. label!
  270.  
  271. These were explained above.  Note that the reference completions can be 
  272. instigated by command completion on, 'Fig' 'Chap' 'Eq.'  'Sec', ...  which 
  273. insert the standard label prefix 'fig:' 'chap:' 'eq:' 'sec:' as 
  274. appropriate.  If you complete with no prefix, then any label will match; if 
  275. you have a prefix then only those which match will be suggested.
  276.  
  277.               TeX citation completion.  
  278.  
  279. Type '\cite{Darley19<cmd-Tab>' and the command is completed with a matching 
  280. citation entry from one of your '.bib' database files.  If there are 
  281. multiple possibilities, then you are prompted with a list from which to 
  282. choose.  (Note: if you find the selection box a bit narrow, it is possible
  283. to edit Alpha using ResEdit to increase its size).  Depending upon the
  284. value of a TeX flag, the list can include the titles of each choice,
  285. making it more obvious to you which is correct.
  286.  
  287.               TeX environment completion: 
  288.  
  289. \begin{} \end{} pairs with synchronisation of the parameter, and template 
  290. generation of the body.
  291.  
  292. You can complete '\begin<cmd-Tab>' followed by 'equ<cmd-Tab>' to the
  293. following:
  294.  
  295.     \begin{equation}
  296.         •
  297.         \label{eq:•}
  298.     \end{equation}
  299.     •
  300.  
  301. You have a choice between the double-completion, as above, or just typing
  302. '\begin{equation}<cmd-Tab>' which will do the job in one go.
  303.  
  304. Similar things work for 'itemize' 'enumerate' etc.  Of particular use
  305. are the completions for 'figure' environments, from which you can enter
  306. ordinary figures, floating figures, and a large number of sub-figure 
  307. configurations (2 figures side-by-side, a block of 4,...).  For instance,
  308. a handful of key-presses will give you this:
  309.  
  310.     \begin{figure}
  311.         \centering
  312.         \subfigure[•“subfig caption”]{\label{fig:•}%
  313.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  314.         \subfigure[•“subfig caption”]{\label{fig:•}%
  315.             \includegraphics[width=\figstwo]{•“graphics file”}}\\
  316.         \subfigure[•“subfig caption”]{\label{fig:•}%
  317.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  318.         \subfigure[•“subfig caption”]{\label{fig:•}%
  319.             \includegraphics[width=\figstwo]{•“graphics file”}}%
  320.         \caption•“[short caption for t.o.f.]”{•“caption”}
  321.         \label{fig:•}
  322.     \end{figure}
  323.     •
  324.  
  325. For these to work, you must use the correct LaTeX packages (graphics, 
  326. floatingfigure or subfigure as appropriate, although the code will 
  327. automatically insert the correct 'usepackage' specifications for you if 
  328. desired), and you may need the following definitions in your LaTeX 
  329. preamble:
  330.  
  331.     \newlength{\goodspace}
  332.     \newlength{\goodspacethree}
  333.     \newlength{\goodspacefour}
  334.     \newlength{\figstwo}
  335.     \newlength{\figsthree}
  336.     \newlength{\figsfour}
  337.     
  338.     \setlength{\goodspace}{\subfigtopskip+\subfigbottomskip}
  339.     \setlength{\goodspacethree}{\goodspace}
  340.     \setlength{\goodspacefour}{\goodspace*\real{0.6}}
  341.     
  342.     \newcommand{\goodgap}{\hspace{\goodspace}}
  343.     \newcommand{\goodgaptwo}{\goodgap}
  344.     \newcommand{\goodgapthree}{\hspace{\goodspacethree}}
  345.     \newcommand{\goodgapfour}{\hspace{\goodspacefour}}
  346.     
  347.     \setlength{\figstwo}{(\linewidth-\goodspace)/2-1pt}
  348.     \setlength{\figsthree}{(\linewidth-\goodspace *2)/3-1pt}
  349.     \setlength{\figsfour}{(\linewidth-\goodspace *\real{1.8})/4-1pt}
  350.  
  351. These allow good alignment and spacing for most subfigure combinations
  352. without the need for manual intervention.  
  353.  
  354. Some environments can contain an arbitrary number of items.  In this case, 
  355. hitting 'shift-option-i' will add an item.  Here we turn this:
  356.  
  357.     \begin{description}
  358.         \item[First one] here's the description
  359.         
  360.         \item[•“name”] •“description”
  361.         
  362.     \end{description}
  363.     •
  364.  
  365. into:
  366.  
  367.     \begin{description}
  368.         \item[First one] here's the description
  369.         \item[•] •
  370.         
  371.         \item[•“name”] •“description”
  372.         
  373.     \end{description}
  374.     •
  375.  
  376. Similar entries work correctly for itemised, enumerated, aligned,... 
  377. environments.
  378.  
  379.               File-name completion:
  380.  
  381. Useful for Shel mode, this allows you to type a partial directory or 
  382. filename and hit cmd-Tab to have it extended as much as possible.
  383.  
  384.               Tcl Variable Completion:
  385.  
  386. Tcl variables are often referenced with '$var' or just 'var' or '${var}'.  
  387. You can complete between any of these types.  A local search for a match is 
  388. done and the closest match inserted.  Again you can cycle through other 
  389. matches with <cmd-Tab>
  390.  
  391.               Word Completion: 
  392.  
  393. if none of the above succeeded then the current word is completed to copy 
  394. nearby words (variable names) in the file.  Again, repeated presses will 
  395. cycle through other possibilities.
  396.  
  397. In any form of text in any mode, if no mode-specific completion matches, 
  398. then any local word can match, complete and be cycled through as usual.
  399.  
  400.             Template insertion
  401.  
  402. You'll notice in a lot of the above examples that bullets '•' are inserted 
  403. into the text.  In fact the user has a choice of four different levels of 
  404. interaction with the template insertion procedures.  You can change this 
  405. using the universal preferences dialog (in the config menu).  You can move
  406. from one insertion point to the next using the 'tab' key; move backwards 
  407. with 'shift-tab' and jump to any insertion point with 'ctrl-tab'.  If you 
  408. don't like these key bindings, an alternative set is available by a change 
  409. in the universal preferences.  You can also choose the colour of the
  410. inserted bullets/prompts.
  411.  
  412.             The Electric Menu
  413.  
  414. By default all items in the ${mode}electrics array are inserted into a new 
  415. menu.  This allows you to insert them, and get a feel for a small number 
  416. of the completions which exist.  Also at the bottom of the menu are items 
  417. for each of the standard key bindings these routines use, to help you to 
  418. remember them.
  419.  
  420.             Completion feedback
  421.  
  422. Help me to help you!
  423.  
  424. Completions for some common items just don't currently exist.  So if you 
  425. try to complete something and it doesn't work, why not write a completion 
  426. for it?  Once you have assembled a few, mail them to me (preferably 
  427. binhex'd, since bullets '•' don't travel well by ASCII mail).  I'd
  428. particularly like completions for other modes.
  429.  
  430.             Speed
  431.  
  432. Alpha has some limitations which means some aspects of Vince's Additions
  433. are a little bit slow (on low-end machines, at least).
  434.  
  435. Two things you can do to alleviate this: first, in modes for which Tab (or 
  436. ctrl-j under the alternative bindings) ALWAYS means to go the next template 
  437. stop and never means to indent the current line, define a new mode variable 
  438. 'tabNeverIndents' by adding the following line to your "prefs.tcl":
  439.   
  440.     newPref f tabNeverIndents 1 MODE
  441.  
  442. where 'MODE' is 'TeX', 'Java', 'HTML' or whatever.  You'll need to add one
  443. such line for each relevant mode.
  444.  
  445. The second thing you can do is to mail Pete Keleher to ask for new features 
  446. and fixes which will improve this problem.  What is needed is:
  447.   (i) GetTMarkPos ?-w win? name  --- find pos of Tmark 'name' in window
  448.   (ii) GetTMarks ?-w win?        --- list Tmarks in given window only
  449.   (iii) curWin ?-f?              --- return uppermost window name (full path)
  450.   (iv) a bug fix so 'GetTMarks' doesn't think non-file windows are in 
  451.   Alpha's HOME directory.
  452.   
  453. ================================================================================
  454.